<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>

  let names = ['James', 'Bob', 'Alice', 'Bob', 'John'];
  let countedNames = names.reduce((acc, cur) => {
    if (cur in acc) {
      acc[cur]++;
    } else {
      acc[cur] = 1;
    }
    return acc;
  }, {})
  let people = [
    {name: 'Alice', age: 21},
  {name: 'James', age: 20},
  {name: 'John', age: 20}
  ];
  const groupBy = (objectArray, property)=>{
    return objectArray.reduce((acc, cur)=>{
      let key = cur[property];
      if (!acc[key]) {
        acc[key] = [];
      } else {
        acc[key].push(cur);
      }
      return acc;
    }, {})
  };
  let gruopedPeople = groupBy(people, 'age');
</script>
</body>
</html>
